import { CHANGE_INPUT, CHANGE_LIST, ADD_ITEM, DEL_ITEM } from './homeActiveTypes';

let defaultState = {
  inputValue: '默認值',
  list: []
}
export default (state = defaultState, action) => {
  if (action.type === CHANGE_INPUT) {
    let initState = JSON.parse(JSON.stringify(state));
    initState.inputValue = action.value;
    return initState;
  }
  if (action.type === CHANGE_LIST) {
    let initState = JSON.parse(JSON.stringify(state));
    initState.list = action.value;
    return initState;
  }
  if (action.type === ADD_ITEM) {
    let initState = JSON.parse(JSON.stringify(state));
    initState.list.push({ title: state.inputValue })
    initState.inputValue = '';
    return initState;
  }
  if (action.type === DEL_ITEM) {
    let initState = JSON.parse(JSON.stringify(state));
    initState.list.splice(action.value, 1);
    return initState;
  }
  return state;
}